nice_things/storage/destructor_add.sh
destructor_add
Since 0.3.0 · Source
import "{ destructor_add }" from nice_things/storage/destructor_add.sh
Synopsisdestructor_add <command> [<arg>…]
Configuration
–
Description
Register a destructor command/function to be executed on program exit. This function can be invoked many times to register many destructors. Once added, destructors cannot be removed, so destructor functions should ideally be idempotent.
This function registers a trap, taking care to make sure it is executed on any shell no matter if the process exits normally or is terminated by a signal.
Note
When destructors are in use, traps for
EXITand the usual termination signalsHUP INT QUIT ABRT ALRM TERMshould not be configured manually, or they will override the destructors configured through this function.
Options
–
Operands
<command>: The destructor command.<arg>: Optional argument to<command>.
Stdin
–
Stdout
–
Stderr
–
Exit status
0: Successful completion.11: Invalid or missing arguments (abort).
Abort
Aborts on invalid or missing arguments.
Usage examples
# Delete a temporary file on exit
destructor_add rm -f /path/to/temp/file